package TankGame4_0;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import TankGame1_.Hero;
import TankGame2_0.Shot;
import TankGame3_.MyPanel3;

public class Setting extends JFrame implements ActionListener{

	JPanel up,ss;
	JLabel U;
	JButton [] Plus= new JButton[4];
	JButton [] Cut = new JButton[4];
	JLabel [] Kind = new JLabel[4];
	Hero hero;
	
	
//	public static void main(String [] s){
//		Setting d = new Setting(hero);
//	}
//	
	
	
	public Setting(Hero hero){
		this.hero = hero;
		try {
			U = new JLabel((Icon) new ImageIcon(ImageIO.read(getClass().getResource("/images/100.jpg"))));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		for (int i=0;i<4;i++){
//			Plus[i].setName("+");�������� ��Ϊ�����İ�ť��û���ڴ棬ֻ�Ƿ�����һ���������
//			Cut[i].setName("-");
			Plus[i] = new JButton("+");
			Cut[i] = new JButton("-");
		}
		Kind[0] = new JLabel("�ӵ����ٶȣ�");//+Shot.getSpeed()
		Kind[1] = new JLabel("̹�˵��ٶȣ�");//+hero.getSpeed()
		Kind[2] = new JLabel("̹������ֵ��");//+this.hero.getLife()
		Kind[3] = new JLabel("���ֵ�������");//+MyPanel3.getEnSize()
		
		up = new JPanel();
		ss = new JPanel();
		
		up.add(U);
		
		ss.setLayout(new GridLayout(4,3,0,0));
		for(int i=0;i<4;i++){
			ss.add(Kind[i]);
			ss.add(Plus[i]);
			ss.add(Cut[i]);
			Plus[i].addActionListener(this);
			Cut[i].addActionListener(this);
		}
		Plus[0].setActionCommand("�ӵ�����");
		Plus[1].setActionCommand("̹������");
		Plus[2].setActionCommand("����");
		Plus[3].setActionCommand("�ӵ���");
		Cut[0].setActionCommand("�ӵ�����");
		Cut[1].setActionCommand("̹�˽���");
		Cut[2].setActionCommand("����");
		Cut[3].setActionCommand("������");
		
		this.add(up,BorderLayout.NORTH);
		this.add(ss,BorderLayout.CENTER);
		this.setLocation(800,300);
		this.setSize(260, 280);
		this.setTitle("Setting");
//		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent B) {
		// TODO Auto-generated method stub
		if(B.getActionCommand().equals("�ӵ�����")){
			Shot.setSpeed(Shot.getSpeed()+1);
		}
		 if(B.getActionCommand().equals("̹������")){
			hero.setSpeed(hero.getSpeed()+1);
		}
		 if(B.getActionCommand().equals("����")){
			this.hero.setLife(this.hero.getLife()+1);
		}
		 if(B.getActionCommand().equals("�ӵ���")){
			MyPanel3.setEnSize(MyPanel3.getEnSize()+1);
		}
		 if(B.getActionCommand().equals("�ӵ�����")){
			Shot.setSpeed(Shot.getSpeed()-1);
		}
		 if(B.getActionCommand().equals("����")){
			this.hero.setLife(this.hero.getLife()-1);
		}
		 if(B.getActionCommand().equals("������")){
			MyPanel3.setEnSize(MyPanel3.getEnSize()-1);
		}
		 if(B.getActionCommand().equals("̹�˽���")){
			hero.setSpeed(hero.getSpeed()-1);
		}
	}
}
